package nyttHus.model3D;

import byggeTegner.ByggeTegner;
import context.*;

import nyttHus.NyttHusProsjekt;

import model3D.Model3D;
import object3D.Block;
import geometry3D.Point3D;

import model2D.Model2D;
import object2D.GroupObject;
import object2D.RectangleObject;
import geometry2D.MetricPoint2D;

import util.FillStyle;

//Java 3D
import javax.media.j3d.Group;

import java.awt.Color;
import org.json.JSONException;

// ***************************************************************************
// *** CLASS: AvfallSkur
// ***************************************************************************
public class AvfallSkur extends Model3D implements Context.Constants,NyttHusProsjekt.Constants
{ //private static final boolean DEBUG=true; // Overriding .Constants.DEBUG
	
  private static final double avfallSkurWidth=3.00;
  private static final double avfallSkurDepth=1.50;
  private static final double avfallSkurHeight=2.10;

  public Block avfallSkur;

  // *************************************************************************
  // *** CONSTRUCTOR: AvfallSkur
  // *************************************************************************
  public AvfallSkur(int subProject,boolean etterDetteTiltak)
  { super(NyttHusProsjekt.avfallSkurNordVest,subProject,etterDetteTiltak);
    define3DModel();
  }
  
  public static double getWidth() { return(avfallSkurWidth); }
  public static double getDepth() { return(avfallSkurDepth); }
  public static double getHeight() { return(avfallSkurHeight); }

  // *************************************************************************
  // *** METHOD: addBebygdAreal
  // *************************************************************************
  public void addBebygdAreal(Model2D objectModel,double vinkel,Color color,boolean withLabels) throws JSONException
  { GroupObject group=new GroupObject(objectModel,"BYAAvfallSkur");
    MetricPoint2D pGar=this.getP0().toPoint2D(ABOVE);
    if(vinkel!=0) group.setRotate(Math.toRadians(vinkel),pGar.getX(),pGar.getY());
    FillStyle oldFill=ByggeTegner.getCurrentFill();
    ByggeTegner.setCurrentFill(new FillStyle(color));
    populateModel2D(objectModel,withLabels);
    ByggeTegner.setCurrentFill(oldFill);
    objectModel.setCurrentGroup(group.getParentGroup()); // Terminate sub-group
  }

  // *************************************************************************
  // *** METHOD: populateModel2D
  // *************************************************************************
  private void populateModel2D(Model2D objectModel,boolean withLabels) throws JSONException
  {	MetricPoint2D pSkur=getP0().toPoint2D(ABOVE);
    objectModel.addChild(new RectangleObject(objectModel,pSkur.getX(),pSkur.getY(),AvfallSkur.getWidth(),AvfallSkur.getDepth()));
//    if(withLabels)
//    { String[] lines={"GARASJE","P: 1 bil","BYA = 13 m2"};
//      objectModel.addTextLines(lines,pGar.add(0.5,0.75),FontStyle.defaultStyle);
//    }
  }


  private void define3DModel()
  { Point3D p0=this.getP0();  // NOTE: p0 is lower back left corner in 3D coordinate space
    avfallSkur=new Block("AvfallSkur",p0.addY(avfallSkurHeight),avfallSkurWidth,avfallSkurHeight,avfallSkurDepth);
  }


  // ***************************************************************************
  // *** METHOD: addModel3D
  // ***************************************************************************
  public void addModel3D(Group model)
  { model.addChild(avfallSkur.getModel3D(murAppearance));
  }

}